package com.cd.system.jpa.repository;

import com.cd.common.domain.SysUser;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;


/**
 * @Description used as a test repository
 * @Author lqq
 * @Date 2023/10/31 15:15
 **/
@Repository("userDao")
@Transactional
public interface UserRepository extends CrudRepository<SysUser,Long>{
    //a lot of test example,some test cases
    @Query("select user FROM SysUser user WHERE user.userName = ?1")
    SysUser selectUserByUserName(String username);

    @Query("update SysUser lu SET lu.nickName = ?1 where lu.userId =?2")
    @Modifying
    int updateUserByUserName(String name,Long id);

    Optional<SysUser> findByUserNameEquals(String username);

    boolean existsByUserNameAndDelFlagNot(String userName, String delFlag);


    @Query("select user FROM SysUser user")
    List<SysUser> findAll();






}
